package ija.model.players;

import ija.model.types.FigureColor;
import ija.model.types.FigureDirection;

/**
 * 
 * @author Radek Necas, xnecas18
 */
public class RemotePlayer extends Player {
	private String ip;
	private int port;
	private ConnectType type;

	public static enum ConnectType {
		INITIATOR, LISTENER;

		public static ConnectType getFromString(String s) {
			if (s.equalsIgnoreCase("INITIATOR")) {
				return INITIATOR;
			} else if (s.equalsIgnoreCase("LISTENER")) {
				return LISTENER;
			}

			return null;
		}

	}

	public RemotePlayer() {
		super();
	}

	public RemotePlayer(String name, FigureColor color, FigureDirection direction,
			ConnectType connectType, String ipAddress, int port) {
		super(name, color, direction);
		this.ip = ipAddress;
		this.port = port;
		this.type = connectType;
	}

        public RemotePlayer(String name, String ipAddress, int port) {
            super();
            this.name = name;
            this.ip = ipAddress;
            this.port = port;
            this.type = null;
        }
        
	public void setIp(String ip) {
		this.ip = ip;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setConnectType(ConnectType t) {
		this.type = t;
	}

	public String getIp() {
		return this.ip;
	}

	public int getPort() {
		return this.port;
	}

	public ConnectType getConnectType() {
		return this.type;
	}

	@Override
	public void copyFrom(Player p) {
		super.copyFrom(p);
		if (p instanceof RemotePlayer) {
			this.setPort(((RemotePlayer) p).getPort());
			this.setIp(((RemotePlayer) p).getIp());
		}
	}

	@Override
	public RemotePlayer duplicate() {
		RemotePlayer p = new RemotePlayer();
		p.copyFrom(this);
		return p;
	}

	@Override
	public String toString() {
		String s = super.toString();
		s += " address: " + this.getIp() + ":" + this.getPort();
		return s;
	}

}
